package red.stu.mc.mod.codeblock.block;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockLoader {
	
	public static BlockCodeBlock codeBlock = new BlockCodeBlock();
	public static BlockEventBlock eventBlock = new BlockEventBlock();
	public static BlockExceptionBlock exceptionBlock = new BlockExceptionBlock();
	
	public BlockLoader(FMLPreInitializationEvent event) {
		register(codeBlock, "code_block");
		register(eventBlock, "event_block");
		register(exceptionBlock, "exception_block");
	}
	
	@SideOnly(Side.CLIENT)
	public void initRenders() {
		registerRender(codeBlock);
		registerRender(eventBlock);
		registerRender(exceptionBlock);
	}
	
	// register block and block.item
	private void register(Block block, String name) {
		ForgeRegistries.BLOCKS.register(block.setRegistryName(name));
		ForgeRegistries.ITEMS.register(new ItemBlock(block).setUnlocalizedName(block.getUnlocalizedName()).setRegistryName(block.getRegistryName()));
	}
	
	// register block model
	@SideOnly(Side.CLIENT)
	private void registerRender(Block block) {
		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, 
				new ModelResourceLocation(block.getRegistryName(), "inventory"));
	}
	
}
